<template>
    <div>
        <van-nav-bar title="补货订单" left-arrow @click-left="backSup"></van-nav-bar>
        <van-tabs
                class="order-tab"
                v-model="active"
                title-active-color="FBA86"
                color="#FBA86"
                @click="changeStatus"
        >
            <van-tab title="发起的订单"></van-tab>
            <van-tab title="收到的订单"></van-tab>
            <div v-for="item in orderList" :key="item.orderId">
                <div v-for="goods in item.items" :key="goods.id">
                    <div class="order-header">
                        <!--                    <p v-if="active==0">{{item.parentNickname}} : {{item.parentTelephone}}</p>-->
                        <!--                    <p v-else>{{item.memberNickname}} : {{item.memberTelephone}}</p>-->
                        <p>{{item.orderNo}}</p>
                        <span v-if="item.status==1">待支付</span>
                        <span v-else-if="item.status==2">已确认</span>
                        <span v-else>{{item.statusDesc}}</span>
                    </div>
                    <div class="cart-goods-item">
                        <div class="pd-images">
                            <img v-lazy="goods.goodsImage" alt/>
                        </div>
                        <div class="pd-info">
                            <div class="pd-title">{{goods.goodsName}}</div>
                            <div class="pd-sku">
                                <p class="sku-info">数量：{{goods.quantity}}</p>
                                <p class="sku-info">单价：<span style="color: red">￥{{goods.currentUnitPrice}}</span></p>
                                <p class="sku-info">
                                    时间：{{item.createTime}}
                                </p>
                                <p class="suk-info" style="margin-top: 10px">
                                    <van-button
                                            style="float: right;margin-right: 5px; padding: 0 5px"
                                            size="mini"
                                            type="default"
                                            round
                                            v-if="active==0&&item.status == 10"
                                            @click="orderCancel(item.orderId)"
                                    >取消订单
                                    </van-button>
                                    <van-button
                                            style="float: right;margin-right: 5px; padding: 0 5px"
                                            size="mini"
                                            type="danger"
                                            round
                                            v-if="active==0&&item.status == 10"
                                            @click="pay(item)"
                                    >立即支付
                                    </van-button>
                                </p>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div v-if="orderList.length==0" class="none">
                <img src="../../assets/imgList/none.jpg"/>
                <p>这里什么也没有</p>
            </div>
            <van-dialog v-model="show">
                <img src="../../assets/imgList/none.jpg"/>
            </van-dialog>
        </van-tabs>
    </div>
</template>

<script>
    import {
        Cell,
        Row,
        Col,
        List,
        Card,
        Tabs,
        Tab,
        Toast,
        Tag,
        Dialog
    } from "vant";
    import api from "@/utils/restful";

    export default {
        components: {
            [Cell.name]: Cell,
            [Row.name]: Row,
            [Col.name]: Col,
            [List.name]: List,
            [Card.name]: Card,
            [Tabs.name]: Tabs,
            [Tab.name]: Tab,
            [Toast.name]: Toast,
            [Tag.name]: Tag,
            [Dialog.name]: Dialog
        },
        data() {
            return {
                active: 0,
                orderList: [],
                show: false,
                paymentQrcode: "",
                userInfo: {},
                orderInfo: {}
            };
        },
        mounted() {
            this.initGetOrder();
            this.getUserInfo();
        },
        methods: {
            initGetOrder() {
                this.orderList = [];
                if (this.active == 0) {
                    this.getMyOrderList();
                } else {
                    this.getConfirmOrderList();
                }
            },
            getMyOrderList(order_state) {
                this.$axios({
                    method: "get",
                    url: api.goodsOrder,
                    params: {
                        token: localStorage.getItem("token")
                    }
                }).then(res => {
                    this.orderList = res.data;
                });
            },
            getConfirmOrderList() {
                this.$axios({
                    method: "get",
                    url: api.confirmOrderList,
                    params: {
                        token: localStorage.getItem("token")
                    }
                }).then(res => {
                    this.orderList = res;
                });
            },
            payment(ordersId) {
                console.log(ordersId);
                this.show = true;
                this.$axios({
                    method: "get",
                    url: api.getPaymentQRcode,
                    params: {
                        token: localStorage.getItem("token"),
                        ordersId: ordersId
                    }
                }).then(res => {
                    this.paymentQrcode = res;
                });
            },
            pay(order) {
                this.orderInfo.id = order.orderNo;
                this.orderInfo.paymentPrice = order.paymentPrice;
                this.$router.push({
                    name: "OnlinePay",
                    params: {orderInfo: this.orderInfo}
                });
            },
            orderCancel(orderId) {
                this.$dialog.confirm({
                    message: "是否取消当前订单？",
                    confirmButtonText: "确定",
                    cancelButtonText: "取消",
                    confirmButtonColor: "#f00"
                }).then(() => {
                    this.$axios({
                        method: "get",
                        url: api.conventionOrderCancel,
                        params: {
                            token: localStorage.getItem("token"),
                            orderId: orderId
                        }
                    }).then(res => {
                        Toast(res.msg);
                        this.initGetOrder();
                    });
                })
            },

            changeStatus(index, title) {
                this.initGetOrder();
            },
            backSup() {
                // this.$router.go(-1);
                this.$router.push({path: "/"});
            },
            getUserInfo() {
                this.$axios({
                    method: "get",
                    url: api.memberInfo,
                    params: {
                        token: localStorage.getItem("token")
                    }
                }).then(res => {
                    console.log(res);
                    this.userInfo = res.data
                })
            }

        }
    };
</script>

<style lang="less" scoped>
    @import "~style/common.less";

    .order-header {
        display: flex;
        padding: 15px;
        padding-bottom: 0;
        background-color: #fff;
        border-top: 1px solid #eee;
        justify-content: space-between;
        .font-dpr(12px);

        span {
            color: @priColor;
        }
    }

    .order-bottom {
        padding: 15px;
        background-color: #fff;
        text-align: right;
        .font-dpr(12px);

        .order-btn {
            width: 100%;
            display: flex;
            justify-content: flex-end;
            align-items: center;
            background-color: #fff;
            height: 44px;

            li {
                .font-dpr(12px);
                // border:1Px solid @priColor;
                line-height: 24px;
                height: 24px;
                border-radius: 12px;
                padding: 0 8px;
                margin-left: 10px;
                color: @tipColor;

                &:nth-child(1) {
                    color: @priColor;
                    border: 1px solid @priColor;
                }

                &:nth-child(2) {
                    // color: @tipColor;
                    border: 1px solid @tipColor;
                }
            }
        }
    }

    .cart-goods-item {
        background-color: #fff;
        // margin-top: 10px;
        // width: 90vw;
        padding: 10px 15px;
        // border: 1px solid #f9f;
        .flexbox(flex-start, center, row, nowrap);
        justify-content: space-between;
        // padding: 5px;
        // border-bottom: 1px solid @borderColor;
        &:last-child {
            border-bottom: none;
        }

        .order-info {
            border: 1px solid red;
            position: relative;
            margin-top: 10px;
            padding: 17px 25px;
            color: @fontColorH3;
            .font-dpr(14px);
            font-weight: normal;
            background-color: #fff;

            &::after {
                position: absolute;
                content: "";
                display: block;
                width: 3px;
                height: 14px;
                left: 15px;
                top: 21px;
                background-color: @priColor;
            }

            p {
                .font-dpr(12px);
                color: @fontColorP;
                font-weight: 300;
                margin-top: 12px;
            }
        }

        .pd-images {
            border: 1px solid @borderColor;
            // border: 1px solid #f0f;

            margin: 0 10px 0 5px;
            flex: 1;
            // max-width: 100px;
            img {
                width: 75px;
                height: 75px;
            }
        }

        .pd-info {
            flex: 3;
            // .flexbox(flex-start, space-between, column, wrap);
            -width: 68% !important;
            // flex: initial;
            // border: 1px solid blue;

            .pd-title {
                position: relative;
                text-overflow: ellipsis;
                overflow: hidden;
                display: -webkit-box;
                /* autoprefixer: off */
                -webkit-box-orient: vertical;
                /* autoprefixer: on */
                -webkit-line-clamp: 2;

                max-width: 100%;
                .font-dpr(12px);
                color: @fontColorH3;
            }

            .pd-sku {
                padding: 5px 0;
                line-height: 1.5;
                .font-dpr(11px);
                color: @tipColor;
            }

            .pd-price {
                margin-top: 10px;

                .total {
                    .font-dpr(14px);
                    color: @secColor;
                }

                .flexbox(space-between, center, row, nowrap);
                flex: initial;

                /deep/ .van-stepper {
                    // z-index: 999;
                    .flexbox(space-between, center, row, nowrap);
                    flex: initial;
                    border-radius: 2px;
                    // border: 1px solid #f0f;
                    max-height: 16px;
                    width: 2rem;

                    .van-stepper__minus,
                    .van-stepper__plus {
                        border: none;
                        max-height: 16px;
                        background-color: @bgColor;
                    }

                    .van-stepper__input {
                        border: 1px solid @borderColor;
                        // border: 1px solid #f00;
                        max-height: 16px;
                        background-color: @bgColor;
                        // border: none;
                        outline: none;
                        text-align: center;
                        padding: 0;
                        min-width: 40%;
                        .font-dpr(11px);
                    }

                    .van-stepper__minus--disabled {
                        background-color: @bgColor;
                    }
                }
            }

            .num {
                .font-dpr(12px);
            }
        }
    }

    .none {
        height: calc(100vh - 90px);
        box-sizing: border-box;
        padding-top: 100px;
        text-align: center;

        img {
            width: 200px;
            height: 200px;
        }

        p {
            margin-top: 20px;
            padding: 15px 0;
            font-size: 16px;
            color: #999;
        }
    }
</style>

